#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File        :   150. 逆波兰表达式求值.py    
@Contact     :   lhouctcs@163.com
@License     :   MIT
@Time        :   2023/2/12 20:38
@Author      :   lhou 
@Version     :   0.1.0
@Description :
"""


# import lib
class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        l = []
        for i in tokens:
            if i == "+":
                a = l.pop()
                b = l.pop()
                l.append(b + a)
            elif i == "-":
                a = l.pop()
                b = l.pop()
                l.append(b - a)
            elif i == "*":
                a = l.pop()
                b = l.pop()
                l.append(b * a)
            elif i == "/":
                a = l.pop()
                b = l.pop()
                l.append(int(b / a))
            else:
                l.append(int(i))
        return l[0]

# class Solution:
#     op_map = {'+': add, '-': sub, '*': mul, '/': lambda x, y: int(x / y)}

#     def evalRPN(self, tokens: List[str]) -> int:
#         stack = []
#         for token in tokens:
#             if token not in {'+', '-', '*', '/'}:
#                 stack.append(int(token))
#             else:
#                 op2 = stack.pop()
#                 op1 = stack.pop()
#                 stack.append(self.op_map[token](op1, op2))  # 第一个出来的在运算符后面
#         return stack.pop()
